package org.example.httpserver.controller;

import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RestController
public class ImageController {

    @GetMapping("/getImage")
    public ResponseEntity<Resource> getImage(@RequestParam String name) throws IOException {

        String path = "C:\\Users\\lqz\\Pictures\\Saved Pictures\\" + name + ".jpg";
        Resource image = new FileSystemResource(path);
        HttpHeaders headers = new HttpHeaders();
        headers.add("Content-Type", "image/jpeg");
        return new ResponseEntity<>(image, headers, HttpStatus.OK);
    }
}
